<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" xmlns:oso="http://osoftware.com/facelets" template="/WEB-INF/templates/mainEditLayout.xhtml">

	<ui:define name="title">
			#{resourceBundle['bill.title']}
	</ui:define>

	<ui:define name="editFields">
		<h:outputText value="#{resourceBundle['bill.date']}" />
		<h:outputText id="date" value="#{billModel.date}">
			<f:convertDateTime pattern="dd/MM/yyyy" />
		</h:outputText>
		<h:outputText value="" />

		<oso:selectOneMenu id="patient" label="#{resourceBundle['bill.patient']}" value="#{billModel.patient}" converter="patientConverter" items="#{billModel.selectablePatients}" itemLabel="fullName"
			required="true">
			<p:ajax event="change" listener="#{billController.onPatientChange}" update="patientPrepaid" />
		</oso:selectOneMenu>


		<oso:selectOneMenu id="paymentType" label="#{resourceBundle['bill.paymentType']}" value="#{billModel.paymentType}" converter="paymentTypeConverter" items="#{billModel.selectablePaymentTypes}"
			required="true" itemLabel="name">
			<p:ajax event="change" update="patientPrepaid" />
		</oso:selectOneMenu>

		<oso:selectOneMenu id="patientPrepaid" label="#{resourceBundle['bill.patientPrepaid']}" value="#{billModel.patientPrepaid}" converter="patientPrepaidConverter" items="#{billModel.patient.prepaids}"
			itemLabel="description" />

		<p:commandButton id="addBillDetail" value="Nuevo" oncomplete="billDetailDialogWV.show();" process="@this" actionListener="#{billController.addBillDetailEvent}" update=":billDetailDialogForm" />

		<p:dataTable id="listTable" var="row" value="#{billModel.editedEntity.billDetails}" paginator="true"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15"
			emptyMessage="#{resourceBundle['list.noData']}" paginatorAlwaysVisible="false">

			<p:column sortBy="#{row.quantity}">
				<f:facet name="header">
					<h:outputText value="#{resourceBundle['billDetail.quantity']}" />
				</f:facet>
				<h:outputText value="#{row.quantity}" />
			</p:column>

			<p:column sortBy="#{row.specialistFee.specialist.fullName}">
				<f:facet name="header">
					<h:outputText value="#{resourceBundle['schedule.specialist']}" />
				</f:facet>
				<h:outputText value="#{row.specialistFee.specialist.fullName}" />
			</p:column>

			<p:column sortBy="#{row.specialistFee.attentionType.name}">
				<f:facet name="header">
					<h:outputText value="#{resourceBundle['bill.specialistFee']}" />
				</f:facet>
				<h:outputText value="#{row.specialistFee.attentionType.name}" />
			</p:column>

			<p:column sortBy="#{row.specialistFee.amount}">
				<f:facet name="header">
					<h:outputText value="#{resourceBundle['billDetail.amount']}" />
				</f:facet>
				<h:outputText value="#{row.specialistFee.amount}" />
			</p:column>

			<p:column sortBy="#{row.specialistFee.attentionType.name}">
				<f:facet name="header">
					<h:outputText value="#{resourceBundle['billDetail.amount']}" />
				</f:facet>
				<h:outputText value="#{row.amount}" />
			</p:column>

			<p:column>
				<ui:insert name="actionColumns" />
				<p:commandLink title="#{resourceBundle['list.header.edit']}" oncomplete="billDetailDialogWV.show();" process="@this" update=":billDetailDialogForm">
					<h:graphicImage value="/resources/images/edit.gif" />
					<f:setPropertyActionListener target="#{billModel.editedBillDetail}" value="#{row}" />
				</p:commandLink>
				<p:commandLink title="#{resourceBundle['list.header.delete']}" oncomplete="billDetailConfirmation.show();" process="@this">
					<h:graphicImage value="/resources/images/delete.gif" />
					<f:setPropertyActionListener target="#{billModel.editedBillDetail}" value="#{row}" />
				</p:commandLink>
			</p:column>
			<p:columnGroup type="footer">
				<p:row>
					<p:column colspan="4" style="text-align:right" footerText="Total:" />
					<p:column footerText="#{billModel.amount}" style="text-align:right" />
					<p:column style="text-align:right" />
				</p:row>
			</p:columnGroup>
		</p:dataTable>
		<p:dialog id="confirmBillDetailDialog" message="#{resourceBundle['popup.confirm']}" header="#{resourceBundle['popup.confirm']}" severity="alert" widgetVar="billDetailConfirmation">

			<p:commandButton id="submitDeleteBillDetailButton" value="#{resourceBundle['btn.delete']}" actionListener="#{billController.confirmDeleteBillDetailEvent}" update=":editForm:listTable"
				oncomplete="billDetailConfirmation.hide();" process="@this" />

			<p:commandButton id="decline" value="#{resourceBundle['btn.cancel']}" onclick="billDetailConfirmation.hide()" type="button" />
		</p:dialog>
	</ui:define>

	<ui:define name="afterForm">
		<ui:include src="billDetail.xhtml"></ui:include>
	</ui:define>

</ui:composition>